package com.example.demo.common;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @author yinbo
 */
public class BaseResponse implements Serializable {
	private static final int CODE_SUCCESS = 200;

	private static final int CODE_FAIL = 500;

	private static final int CODE_ERROR = 500;

	private static final int CODE_NO_LOGIN = 300;

	private static final long serialVersionUID = 1L;

	private Integer status;
	private Boolean result;
	private String message;
	private Map<String,Object> data;

	private BaseResponse(){}

	public static BaseResponse success(){
		BaseResponse baseResponse = new BaseResponse();
		baseResponse.status = CODE_SUCCESS;
		baseResponse.result = true;
		return baseResponse;
	}

	public static BaseResponse fail(){
		BaseResponse baseResponse = new BaseResponse();
		baseResponse.status = CODE_FAIL;
		baseResponse.result = false;
		return baseResponse;
	}

	public BaseResponse data(String key, Object value){
		if (this.data == null){
			data = new HashMap<String,Object>();
		}
		this.data.put(key,value);
		return this;
	}

	public BaseResponse message(String message){
		this.message = message;
		return this;
	}

	@Override
	public String toString() {
		return "BaseResponse{" +
				"status=" + status +
				", result=" + result +
				", message='" + message + '\'' +
				", data=" + data +
				'}';
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Boolean getResult() {
		return result;
	}

	public void setResult(Boolean result) {
		this.result = result;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Map<String, Object> getData() {
		return data;
	}

	public void setData(Map<String, Object> data) {
		this.data = data;
	}

}
